package leetcode.slidwidow;

import java.util.ArrayDeque;

public class Lc1004 {

    public int longestOnes(int[] nums, int k) {
        int ans = 0;
        int i = 0, j = 0, zeroCnt = 0;
        for (; j < nums.length; j++) {
            if (nums[j] == 1) continue;
            ans = Math.max(ans, j - i);
            zeroCnt++;
            while (zeroCnt > k) {
                if (nums[i] == 0)
                    zeroCnt--;
                i++;
            }
        }

        ans = Math.max(j - i, ans);
        return ans;
    }

    public static void main(String[] args) {
        Lc1004 lc1004 = new Lc1004();
        int[] a = {0,0,1,1,1,0,0};
        int k = 0;
        System.out.println(lc1004.longestOnes(a, k));
    }


}
